/**
 * @param {number} x
 * @return {number}
 */
var reverse = function(x) {
    let numRegion=x.toString()
    let ifNegative
    if(numRegion[0]==='-'){
        numRegion=numRegion.slice(1)
        ifNegative=true
    }

    let result = Number(numRegion.split('').reverse().join(''))
    if(ifNegative){
        result = -result
    }


    const min = (-2n)** 31n;
    const max = (2n) **31n - 1n;
    if (result < min || result > max) {
        return 0;
    }
    
    return result

};